<template>
  <div class="chart" ref="chart"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  mounted() {
    this.char = null;
    this.initChart();
  },
  destroyed() {
    this.chart && this.chart.dispose();
  },
  methods: {
    initChart() {
      if (!this.$refs.chart) {
        return;
      }
      const option = {
        title: {
          text: "ECharts 入门示例",
        },
        tooltip: {},
        xAxis: {
          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        },
        yAxis: {},
        series: [
          {
            name: "销量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20],
          },
        ],
      };
      this.$refs.chart.style.height = "280px";
      this.$refs.chart.style.width = getComputedStyle(
        this.$refs.chart.parentNode
      ).width;
      this.chart = echarts.init(this.$refs.chart);
      this.chart.setOption(option);
    },
  },
};
</script>
<style>
.mod-home {
  line-height: 1.5;
}
</style>
